package com.marvels.loanapply.consum.impl;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.alibaba.fastjson.JSONObject;
import com.marvels.common.utils.MarvelsLogUtil;
import com.marvels.dubbo.coreservice.service.ILoanApplyInfoService;
import com.marvels.dubbo.externalservice.service.SendSmsNewService;
import com.marvels.loanapply.consum.LoanapplyConsumerDubboApi;
import com.marvels.loanapply.customer.dto.SendMsgDTO;
import com.marvels.loanapply.customer.dto.SmsTemplateNew;
import com.marvels.loanapply.customerservice.dto.UserBankDTO;

import cn.hutool.core.bean.BeanUtil;

@Service
public class LoanapplyConsumerDubboApiImpl implements LoanapplyConsumerDubboApi {

	@Autowired
	private ILoanApplyInfoService loanApplyInfoService;
	
	@Autowired
	private SendSmsNewService sendSmsNewService;
	
	@Override
	public Map<String, Object> queryLoanInfoByCondition(Map<String, Object> map) {
		try {
			Map<String, Object> info= loanApplyInfoService.queryLoanInfoByCondition(map);
			MarvelsLogUtil.getInstance().info("LoanapplyConsumerDubboApi.queryLoanInfoByCondition direct call success!");
			return info;
		} catch (Exception e) {
			MarvelsLogUtil.getInstance().error("LoanapplyConsumerDubboApi.queryLoanInfoByCondition error", e);
			return null;
		}
	}

	@Override
	public List<UserBankDTO> selectUserBankInfo(Map<String, Object> map) {
		try {
			List<com.dragon.loan.entity.AcUserBank> apiResult= loanApplyInfoService.selectUserBankInfo(map);
			List<UserBankDTO> result = JSONObject.parseArray(JSONObject.toJSONString(apiResult), UserBankDTO.class);
			MarvelsLogUtil.getInstance().info("LoanapplyConsumerDubboApi.selectUserBankInfo direct call success!");
			return result;
		} catch (Exception e) {
			MarvelsLogUtil.getInstance().error("LoanapplyConsumerDubboApi.selectUserBankInfo error", e);
			return null;
		}
	}

	@Override
	public boolean sendMsg(SendMsgDTO sendMsgDTO) {
		try {
			com.marvels.dubbo.externalservice.dto.SendMsgDTO param = new com.marvels.dubbo.externalservice.dto.SendMsgDTO();
			BeanUtil.copyProperties(sendMsgDTO, param);
			boolean result = sendSmsNewService.sendMsg(param);
			MarvelsLogUtil.getInstance().info("LoanapplyConsumerDubboApi.sendMsg direct call success!");
			return result;
		} catch (Exception e) {
			MarvelsLogUtil.getInstance().error("LoanapplyConsumerDubboApi.sendMsg error", e);
			return false;
		}
	}

	@Override
	public SmsTemplateNew getSmsTemplateNew(SendMsgDTO sendMsgDTO) {
		try {
			com.marvels.dubbo.externalservice.dto.SendMsgDTO param = new com.marvels.dubbo.externalservice.dto.SendMsgDTO();
			BeanUtil.copyProperties(sendMsgDTO, param);
			com.fintech.third.model.sms.SmsTemplateNew apiResult = sendSmsNewService.getSmsTemplateNew(param);
			SmsTemplateNew result = JSONObject.parseObject(JSONObject.toJSONString(apiResult), SmsTemplateNew.class);
			MarvelsLogUtil.getInstance().info("LoanapplyConsumerDubboApi.getSmsTemplateNew direct call success!");
			return result;
		} catch (Exception e) {
			MarvelsLogUtil.getInstance().error("LoanapplyConsumerDubboApi.getSmsTemplateNew error", e);
			return null;
		}
	}

}
